var scrollTop;
var documentH;
var windowH;
var boolScrollBottom = false;
var audio;
window.onload = function() {

   

    initAudio();

}

var initAudio = function() {
    audio = $("audio");
    audio[0].src = "http://fwisstaticcontent.fwis2014.com/ethics/audio/Q1.mp3";
    audio[1].src = "http://fwisstaticcontent.fwis2014.com/ethics/audio/Q2.mp3";
    audio[2].src = "http://fwisstaticcontent.fwis2014.com/ethics/audio/Q3.mp3";
    audio[3].src = "http://fwisstaticcontent.fwis2014.com/ethics/audio/Q4.mp3";
    $(audio).each(function(index) {
        $(this).on("ended", function() {
            $("img.say").each(function() {
                this.src = "http://fwisstaticcontent.fwis2014.com/ethics/images/say.jpg";


            })
        })

    })



}


function playOrPaused(index, obj) {


    if (audio[index].paused) {
        Allpause(audio);
        audio[index].play();


        changePlay(obj, index);


        return;
    }
    audio[index].pause();
    changePause(obj, index);

}

function changePlay(obj, index) {



    $(obj).find("img.say")[0].src = "http://fwisstaticcontent.fwis2014.com/ethics/images/say.gif";




}

function changePause(obj, index) {



    $(obj).find("img.say")[0].src = "http://fwisstaticcontent.fwis2014.com/ethics/images/say.jpg";


}

function Allpause(audio) {
    $(audio).each(function() {
        this.pause();
    })
    $("img.say").each(function() {
        this.src = "http://fwisstaticcontent.fwis2014.com/ethics/images/say.jpg";


    })
}
$(function() {



    setTimeout(function() {
        $(".weixinImg").hide();
        $(".weixinImg").fadeOut(function() {
            $(".weixinImg").remove();
        });

        $(".weixinCont").show(function() {
            $(".footer").show();
        });

    }, 2000);

    windowH = $(window).height();


})

$(window).scroll(function() {
    documentH = $(document).height();
    scrollTop = $(document.body).scrollTop() || $(window).scrollTop();;



    if (documentH == scrollTop + windowH && !boolScrollBottom) {

        toBottom();


    }

})

function toBottom() {
    $("#img_ipt").hide();
    $("#img_key_null").show(function() {

        var footerH = $(".footer").height();
        $(".weixinCont").css("padding-bottom", footerH + "px");
        var h = $(document).height() - $(window).height();
        $(document.body).scrollTop(h);

        initialize()


    });



}

var it = 0;
var mytext;

function initialize() {

    boolScrollBottom = true;
    mytext = $("#typing").text();


    var myheight = $("#typing").offsetHeight;
    $("#typing").text("");
    $("#typing").css("height", myheight);
    $(".ipt").show(function() {

        typeit();
    });


}
var t;

function typeit() {

    $("#typing").append(mytext.charAt(it));
    if (it < mytext.length - 1) {
        it++
        t = setTimeout("typeit()", 100);


    } else {
        clearTimeout(t);
        $("#img_key_null").hide();
        $("#img_key").show();
        $(".btnSend").css('display', 'block');
    }
}


$(".btnSend").click(function() {
    $("#img_key").hide();
    $("#img_ipt").show();
    $(".ipt,.btnSend").remove();

    $("#mySay").show(1000, function() {
        $("#lastSay").show(2000, function() {
            $("#cafeipaper").show();
        });
    });


})
$("#cafeipaper").click(function() {

    $("#redpaper").show(function() {


    });
});

$(".close").click(function() {
    $("#redpaper").hide(function() {


    });
})
